proc auth {nick host handle arg} {
global botnick home cryptkey
if {![validuser $handle]} {
  putserv "NOTICE $nick :ERROR - Your user account could not be found in my user partition - you don't have access on me."
  return 0
  }
if {$arg == ""} {
  putserv "NOTICE $nick :ERROR - No Password Specified - You need to specify your password."
  return 0
  }
if {[matchattr $handle D]} {
  putserv "NOTICE $nick :ERROR - Unable To Authenticate - Your user account is disabled therefore you may not auth."
  putlog "\002$handle\002 ($nick) tried to authenticate - the account is disabled - denied authentication."
  putserv "PRIVMSG $home :\002$nick\002 ($handle) ($host) tried to authenticate - the account is disabled - authentication was denied."
  return 0
  }
if {[validuser $handle]} {
set checkpw [getuser $handle PASS]
if {$checkpw == ""} {
  putserv "NOTICE $nick :ERROR - You don't have a password set - Please set a password using /msg $botnick PASS <password>"
  putlog "$nick ($handle) attempted to auth but the user dosen't have a password set - prompting user to setpass."
  return 0
  }
  }
set checkpw [lindex $arg 0]
if {[passwdok $handle $checkpw]} {
  putlog "\002$handle\002 ($nick) sucessfully authenticated."
  putserv "NOTICE $nick :Success - You are now authenticated on $botnick."
  putserv "PRIVMSG $home :\002$nick\002 ($handle) ($host) authenticated sucessfully."
  chattr $handle +A
  save
if [string match global [lindex $arg 1]] {
	putallbots "auth $nick $host $handle [encrypt $cryptkey $checkpw]"
	putserv "NOTICE $nick :Logging you on to all bots on botnet. Please Wait.."
}

  return 0
  }
  putlog "\002$handle\002 ($nick) failed authentication."
  putserv "NOTICE $nick :ERROR - Unable To Authenticate - Failed to authenticate you - invalid password - check your password spelling and remember your password is CaSe SeNsaTive."
  putserv "NOTICE $nick :If you need your new hostmask added type \002/msg $botnick ident <your password>\002"
  putserv "NOTICE $nick :Note that if you use the IDENT command, you MUST use the same nick as you were added to the bot with."
  putserv "PRIVMSG $home :\002$nick\002 ($handle) ($host) failed authentication."
  chattr $handle -A
  save
  }


